﻿using GameData;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using TNet;

public class ServerAction
{

    public static void ServerActionRef(TcpPlayer player, BinaryReader reader)
    {
        //解析
        string ActionName = reader.ReadString();
        switch(ActionName)
        {
            case "注册":
                Logic.RegistLogic(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "登录":
                Logic.LoginLogic(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
        }

    }


}


public class Logic
{
    
    public static void RegistLogic(TcpPlayer player, UserInfo info)
    {
        Console.WriteLine("账户:" + info.username + " 密码：" + info.password);

        //返回数据
        BinaryWriter writer= player.BeginSend(Packet.CommonClientAction);
        writer.Write("注册");
        writer.Write(true);
        player.EndSend();



    }


    public static void LoginLogic(TcpPlayer player,UserInfo info)
    {
        RoleList role = new RoleList();
        role.ID = 0;
        role.Name = "管理元";

        string sendStr = LitJson.JsonMapper.ToJson(role);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("登录");


        writer.Write(sendStr);
        player.EndSend();

    }



}



